package com.tt.task;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Objects;
import java.util.concurrent.ScheduledFuture;

/**
 * @Title: ProdPlanSimTaskUtils
 * @Author zl
 * @Package com.oberyun.zhgc.datascreen.config
 * @Date 2025/7/29 10:41
 * @description: 定时任务工具类
 */
@Component
public class ProdPlanSimTaskUtils {
    @Autowired
    private MethodTaskScheduler methodScheduler;

    /**
     * 创建定时任务
     * @param methodTaskInfo
     * @param corn
     * @param taskId
     */
    public void createTask(MethodTaskInfo methodTaskInfo,String corn,String taskId){
        ScheduledFuture<?> scheduledFuture = methodScheduler.getTaskMaps().get(taskId);
        if(Objects.nonNull(scheduledFuture)){
            methodScheduler.rescheduleMethod(taskId, methodTaskInfo, corn);
        }else{
            methodScheduler.scheduleMethod(taskId, methodTaskInfo, corn);
        }
    }

    /**
     * 重置定时任务
     * @param methodTaskInfo
     * @param taskId
     * @param corn
     */
    public void restartTask(MethodTaskInfo methodTaskInfo,String taskId,String corn){
        methodScheduler.rescheduleMethod(taskId, methodTaskInfo, corn);
    }

    /**
     * 取消定时任务
     * @param taskId
     */
    public void stopTask(String taskId){
        methodScheduler.cancelTask(taskId);
    }



}
